package com.lzq.springblog.service;

import com.lzq.springblog.dao.BlogInfoMapper;
import com.lzq.springblog.dao.UserInfoMapper;
import com.lzq.springblog.model.BlogInfo;
import com.lzq.springblog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Slf4j
@Service
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public UserInfo getUserInfoByName(String username) {
        log.info("执行getUserInfoByName方法");
        return userInfoMapper.selectUserByName(username);
    }

    public UserInfo getUserInfoById(Integer userId) {
        log.info("执行getUsrInfoById方法");
        return userInfoMapper.selectUserById(userId);
    }

    public UserInfo getUserInfoByBlogId(Integer blogId) {
        log.info("执行getUserInfoByBlogId方法");
        BlogInfo blogInfo = blogInfoMapper.selectBlogById(blogId);
        if(blogInfo!=null || blogInfo.getUserId()>0) {
            return userInfoMapper.selectUserById(blogInfo.getUserId());
        }
        return null;
    }


    public Integer addUser(UserInfo userInfo) {
        log.info("执行addUser方法");
        return userInfoMapper.insertUser(userInfo);
    }
}
